OS=$(shell uname)

ifeq ($(OS),Linux)
	FUSE_INCLUDE=/usr/lib/jvm/java-7-openjdk-amd64/include
	FUSE_INCLUDE2=/usr/lib/jvm/java-7-openjdk-amd64/include
	FUSE_LIB=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/
	STOP_CMD=fusermount -u tmp || true
else
	FUSE_INCLUDE=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/include
	FUSE_INCLUDE2=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/include/darwin
	FUSE_LIB=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/server
	STOP_CMD=umount tmp || true
endif

all: pfs-fuse

pfs-fuse: pfs-fuse.c
	gcc -ggdb -I$(FUSE_INCLUDE) -I$(FUSE_INCLUDE2) -L$(FUSE_LIB) -Wall $? `pkg-config fuse --cflags --libs` -o $@ -ljvm
	@echo
	@echo "run it : @LD_LIBRARY_PATH=$(FUSE_LIB) ./pfs-fuse tmp -d"
	@echo "stop it: fusermount -u tmp"
	@echo

clean:
	rm -fr pfs-fuse

run:
	LD_LIBRARY_PATH=$(FUSE_LIB) ./pfs-fuse tmp -f

runs:
	@LD_LIBRARY_PATH=$(FUSE_LIB) ./pfs-fuse tmp -f -s

stop:
	$(STOP_CMD)

javap:
	javap -s -p  -classpath ../target/PFSBuilder*.jar com.pfsbuilder.fuse.FuseStub

test: stop clean pfs-fuse run

